#!/usr/bin/env bash
# projector

if [[ -z "${c_phpstorm}" ]]; then
    f_info 'projector: not install';
    echo > /dev/null;  return;
fi;

# install
if [[ -f "${MEM}/projector" ]]; then f_info 'projector: has install';
else
    f_wait "projector: install";
    f_inst 'projector' 'less libxext6 libxrender1 libxtst6 libfreetype6 libxi6';
    python3 -m pip install -U pip || f_fail 'projector: pip update';
    pip3 install projector-installer || f_fail 'projector: install';
fi;

# nginx
cfg='/home/www/conf'; ngx="${cfg}/@ngx";
if [[ ! -d "${ngx}/demo"  ]]; then
    if [[ ! -d "${cfg}" ]]; then not="${cfg}";
    elif [[ ! -d "${ngx}" ]]; then not="${ngx}";
    else not="${ngx}/demo"; fi;
    mkdir -p "${ngx}/demo" || f_fail 'projector: mkdir ngx conf demo';
    f_mode "${not}" '755' '-' 'www:www';
fi;
src="${RUN}/file/ide/ngx.conf"; tar="${ngx}/demo/ide.conf";
cat "${src}" > "${tar}" || f_fail 'projector: nginx demo config';

# finish
echo > "${MEM}/projector" || f_fail 'projector: save status';
